package com.example.pc.myapplication;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class FirstFragment extends Fragment implements View.OnClickListener{
    private String url;
    private int id;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Bundle arguments = getArguments();
        if (arguments!= null){
            url = arguments.getString("url");
            id = arguments.getInt("id");
        }
    }
    private View layout;
    private View btn_fragment;
    private TextView tv_fragment;
    private EditText et_fragment;
    public FirstFragment() {
        // Required empty public constructor
    }
    public void appendTextView(String s){
        tv_fragment.append(s);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        layout = inflater.inflate(R.layout.fragment_first,container,false);
        btn_fragment = layout.findViewById(R.id.btn_fragment);
        tv_fragment = layout.findViewById(R.id.tv_fragment);
        et_fragment = layout.findViewById(R.id.et__fragment);
        return layout;
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btn_fragment.setOnClickListener(this);
        tv_fragment.setText(url + id);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_fragment:
                String s = et_fragment.getText().toString();
                MainActivity mainActivitry = (MainActivity) getActivity();
                mainActivitry.receiverData(s);
                break;
        }
    }
}
